package com.bskj.common.utils;

import java.util.HashMap;
import java.util.Map;

import org.apache.commons.lang3.StringUtils;

import com.bskj.common.utils.PropertiesLoader;

/**
 * Created by mocaijin on 21/12/2017.
 */
public class Global {
	private static Global global = new Global();

	/**
	 * 保存全局属性值
	 */
	private static Map<String, String> map = new HashMap<>();

	/**
	 * 属性文件加载对象
	 */
	private static PropertiesLoader loader = new PropertiesLoader("config/conf.properties");

	/**
	 * 获取当前对象实例
	 */
	public static Global getInstance() {
		return global;
	}

	/**
	 * 获取配置
	 * @see
	 */
	public static String getConfig(String key, String defaultValue) {
		String value = map.get(key);
		if (value == null) {
			value = loader.getProperty(key);
			map.put(key, value != null ? value : StringUtils.EMPTY);
		}
		if(StringUtils.isBlank(value)) {
			return defaultValue;
		}
		return value;
	}

	public static String getConfig(String key) {
		return getConfig(key, null);
	}

	public static String getWxSendTemplateUrl() {
		return getConfig("WX_SEND_TEMPLATE_URL");
	}
}
